package com.dragon.mmochat.model.playerBet;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.MmochatSerial;
import com.dragon.mmochat.model.enumType.MmochatStoneBetResult;
import com.dragon.mmochat.model.enumType.MmochatStoneBetState;
import com.dragon.mmochat.model.enumType.MmochatStoneBetType;

//石头剪刀布
public class MmochatStoneBet implements Comparable<MmochatStoneBet> {
	private static MmochatSerial serial = new MmochatSerial();
	private int id;
	private int money = 0;// 价格
	private MmochatStoneBetState state = MmochatStoneBetState.创建中;
	private MmochatStoneBetResult result = MmochatStoneBetResult.无;// 比赛结果
	private long createTime = System.currentTimeMillis();// 创建时间
	private long closeTime = System.currentTimeMillis();// 结束时间

	// 我方信息
	private int sendRoleId; // 发布者
	private String sendName;// 发布者名字
	private MmochatStoneBetType sendType;// 发布者出的什么

	// 攻方信息
	private int kickRoleId;// 对方ID
	private String kickName = "";// 对方名字
	private MmochatStoneBetType kickType;// 对方出的什么

	public MmochatStoneBet() {
		id = serial.addAndGetSerialId();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getSendRoleId() {
		return sendRoleId;
	}

	public void setSendRoleId(int sendRoleId) {
		this.sendRoleId = sendRoleId;
	}

	public String getSendName() {
		return sendName;
	}

	public void setSendName(String sendName) {
		this.sendName = sendName;
	}

	public int getMoney() {
		return money;
	}

	public int getWinMoney() {
		return money * (100 - MmochatConstant.stoneBetTax) / 100;
	}

	public void setMoney(int money) {
		this.money = money;
	}

	public MmochatStoneBetState getState() {
		return state;
	}

	public void setState(MmochatStoneBetState state) {
		this.state = state;
	}

	public int getKickRoleId() {
		return kickRoleId;
	}

	public void setKickRoleId(int kickRoleId) {
		this.kickRoleId = kickRoleId;
	}

	public MmochatStoneBetType getSendType() {
		return sendType;
	}

	public void setSendType(MmochatStoneBetType sendType) {
		this.sendType = sendType;
	}

	public String getKickName() {
		return kickName;
	}

	public void setKickName(String kickName) {
		this.kickName = kickName;
	}

	public MmochatStoneBetType getKickType() {
		return kickType;
	}

	public void setKickType(MmochatStoneBetType kickType) {
		this.kickType = kickType;
	}

	public MmochatStoneBetResult getResult() {
		return result;
	}

	public void setResult(MmochatStoneBetResult result) {
		this.result = result;
	}

	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}

	public long getCloseTime() {
		return closeTime;
	}

	public void setCloseTime(long closeTime) {
		this.closeTime = closeTime;
	}

	// 是否创建超时
	public boolean isCreateTimeOut() {
		if (state == MmochatStoneBetState.创建中) {
			return System.currentTimeMillis() - createTime > 10 * MmochatConstant.MS_PER_MINUTE;
		}
		return false;
	}

	// 是否过期
	public boolean isLifeTimeOut() {
		if (state == MmochatStoneBetState.比赛完成) {
			return System.currentTimeMillis() - closeTime > MmochatConstant.stoneBetDoneKeepTime
					* MmochatConstant.MS_PER_HOUR;
		}
		return false;
	}

	@Override
	public int compareTo(MmochatStoneBet o) {
		return (int) (o.getCreateTime() - createTime);
	}
}
